package com.indexingsystem.system.service.impl;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.indexingsystem.boss.Vo.AuthRoleVo;
import com.indexingsystem.boss.Vo.OperationsResultVo;
import com.indexingsystem.boss.Vo.OperationsVo;
import com.indexingsystem.boss.Vo.StatusList;
import com.indexingsystem.boss.admin.mapper.OperationsMapper;
import com.indexingsystem.boss.common.PagedResult;
import com.indexingsystem.boss.entity.Operations;
import com.indexingsystem.boss.utils.BeanUtils;
import com.indexingsystem.system.service.IOperationsService;

@Service
public class OperationsServiceImpl implements IOperationsService {

	@Resource
	private OperationsMapper operationsMapper;

	/**
	 * 通过权限id删除权限信息.
	 */
	@Override
	public int deleteByPrimaryKey(String operationId) {
		return operationsMapper.deleteByPrimaryKey(operationId);
	}

	/**
	 * 新增操作权限.
	 */
	@Override
	public int insertSelective(Operations record) {
		return operationsMapper.insertSelective(record);
	}

	/**
	 * 通过权限id查询权限详情.
	 */
	@Override
	public Operations selectByPrimaryKey(String operationId) {
		return operationsMapper.selectByPrimaryKey(operationId);
	}

	/**
	 * 修改操作权限.
	 */
	@Override
	public int updateByPrimaryKeySelective(Operations record) {
		return operationsMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 获取总记录数.
	 * 
	 * @return
	 */
	@Override
	public Integer getOperationsCount(String queryCriteria) {
		return operationsMapper.getOperationsCount(queryCriteria);
	}
	
	/**
	 * 通过查询条件查询是否已存在.
	 * 
	 * @param queryCriteria
	 * @return
	 */
	@Override
	public List<Operations> getOperationsByQueryCriteria(OperationsVo operationsVo){
		return operationsMapper.getOperationsByQueryCriteria(operationsVo);
	}
	
	/**
	 * 批量启用，禁用权限.
	 * 
	 * @param operationMap
	 * @return
	 */
	@Override
	public int batchUpdateOperationsWithList(List<StatusList> list) {
		return operationsMapper.batchUpdateOperationsWithList(list);
	}

	/**
	 * 操作权限列表显示.
	 */
	@Override
	public PagedResult<Operations> selectOperationsList(String queryCriteria,Integer pageNo, Integer pageSize) {
		pageNo = pageNo == null ? 1 : pageNo;
		pageSize = pageSize == null ? 10 : pageSize;
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage(pageNo, pageSize);
		return BeanUtils.toPagedResult(operationsMapper.selectOperationsList(queryCriteria));
	}
	
	/**
	 * 操作权限列表显示.
	 */
	@Override
	public PagedResult<Operations> selectOperationsListByPage(String queryCriteria,Integer pageNo, Integer pageSize) {
		pageNo = pageNo == null ? 1 : pageNo;
		pageSize = pageSize == null ? 10 : pageSize;
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage(pageNo, pageSize);
		return BeanUtils.toPagedResult(operationsMapper.selectOperationsList(queryCriteria));
	}
	
	/**
	 * 功能管理关联权限列表.
	 * 
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	@Override
	public PagedResult<OperationsResultVo> getOperationsOrFunctioneslist(String queryCriteria,Integer pageNo, Integer pageSize) {
		pageNo = pageNo == null ? 1 : pageNo;
		pageSize = pageSize == null ? 10 : pageSize;
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage(pageNo, pageSize);
		return BeanUtils.toPagedResult(operationsMapper.getOperationsOrFunctioneslist(queryCriteria));
	}

	/**
	 * 批量删除操作权限.
	 */
	@Override
	public int deleteOperationsByIdBatch(List<String> operationIdList) {
		return operationsMapper.deleteOperationsByIdBatch(operationIdList);
	}

	/**
	 * 根据用户ID获取权限的Set集合.
	 * 
	 * @param userId
	 * @return
	 */
	@Override
	public List<AuthRoleVo> findPermissionByUserId(String userId) {
		return operationsMapper.findPermissionByUserId(userId);
	}
	
	/**
	 * 获取操作权限、功能列表/shrio授权使用.
	 * 
	 * @return
	 */
	@Override
	public List<String> queryOperationOrFunctionAll(){
		return operationsMapper.queryOperationOrFunctionAll();
	}
}